var http = require('http')
var querystring = require('querystring')

var postData = querystring.stringify({
  'content': '叶玲：老师讲得很好啊',
  'mid': 348
})

var options = {
  hostname: 'www.imooc.com',
  port: '80',
  path: '/course/docomment',
  method: 'POST',
  headers: {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': postData.length,
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Cookie': 'mc_channel=bdqdrmjt; mc_marking=4ee47ddf7462b1f5bfbb41dc44070bce; UM_distinctid=161382bdf0d3bc-06289a6a4b8a1b-5a442916-1fa400-161382bdf0ec44; CNZZDATA1261110065=1075862102-1517063387-https%253A%252F%252Fwww.baidu.com%252F%7C1517063387; imooc_uuid=d392a173-472f-4e62-900c-c2a506aa6555; imooc_isnew=1; imooc_isnew_ct=1517065856; IMCDNS=0; loginstate=1; last_login_username=81855417%40qq.com; apsid=BlMDdlMmMxYzMyYzVlYmYwYTM0M2IzNmU2MjllNWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjE4Mzk5OQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4MTg1NTQxN0BxcS5jb20AAAAAAAAAAAAAAAAAAAAAAGU1MmIzZTdmMzczOTA1NzVjNzhmYzRkN2FlMjk2YWNh%2BJdsWviXbFo%3DOT; PHPSESSID=0knsje8bsv7dv1aehmrdvi6eq0; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1517065855,1517113675,1517114137; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1517114145; cvde=5a6d514abac48-31',
    'Host': 'www.imooc.com',
    'Origin': 'https://www.imooc.com',
    'Referer': 'https://www.imooc.com/video/8837',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest'
  }
}

var req = http.request(options, function(res) {
  console.log(`status:${res.statusCode}`)
  console.log(`headers:${JSON.stringify(res.headers)}`)
  res.on('data', function(chunk) {
    console.log(typeof chunk)
  })
  res.on('end', function() {
    console.log('评论完毕')
  })
  res.on('error', function(e) {
    console.log('Error:' + e.message)
  })
})
req.write(postData)
console.log(123)
req.end()